package com.ddzj.scaffold.handle;

import com.ddzj.scaffold.utils.JacksonUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:yangzibo
 * @CreateTime:2024-05-16 21:46
 * @Description:
 * @Version:1.0
 **/
public class MyLocalThread {
    // 父子线程共享
    private static final InheritableThreadLocal<Map<String, Object>> GLOBAL_VARIABLE_MAP = new InheritableThreadLocal<>();

    public static void setVal(String name, Object value) {
        if(GLOBAL_VARIABLE_MAP.get() == null){
            GLOBAL_VARIABLE_MAP.set(new HashMap<>());
        }
        GLOBAL_VARIABLE_MAP.get().put(name, value);
    }

    public static void showMap(){
        System.out.println(JacksonUtil.obj2String(GLOBAL_VARIABLE_MAP.get()));
    }

    public static void clear(){
        GLOBAL_VARIABLE_MAP.get().clear();
    }



}
